//Parser object that contains all parser for all skins
//Parser = function Parser() {}; //No need to initialize

/**
 * @function namespace/signatrue - Component type : Control type : Parser.formskin : Parser.impl : html
 * conf - configuration properties for layout
 * prop - properties
 * parentconf - parent element conf
 * parentprop - parent element prop
 */
/*Parser["control:input:default:Json2htmlParser:html"] = function(conf, prop, parentconf, parentprop) {
	Parser.log(JSON.stringify(parentconf));
	Parser.log(JSON.stringify(parentprop));
	return '<span class="label"'+
			(prop["i18ntip-"+Parser.lang] ? (' original-title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
			+ '>'
			+ (prop.required=='1' ? '<span class="xh">*</span>' : '')
			+ '${i18nname-'+Parser.lang+'}</span>'
			+ '<span class="item"><input type="text" '
			+ (prop.disabled=='1' ? ' readonly="readonly"' : '')
			+ (prop.style ? ' style="'+prop.style+'"' : '')
			+ (' class="input '+(prop.classNames ? prop.classNames : '')+'"')
			+ ' databinding="${databinding}"'
			+ (prop.processbinding ? ' binding="'+ prop.processbinding+ '"' : '')
			+ ' maxlength="${maxlength}"' 
			+ ' id="${id}"'
			+ ' desc="${i18nname-'+Parser.lang+'}"'
			+ ' name="${id}"'
			+ ' ng-model="b.'+prop.databinding+'"'
			+ '/></span>';
};*/


/**
 * @function namespace/signatrue - Component type : Control type : Parser.formskin : Parser.impl
 * conf - configuration properties for layout
 * prop - properties
 * parentconf - parent element conf
 * parentprop - parent element prop
 */
Parser["control:input:bootstrap-blue:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log("input conf="+JSON.stringify(conf));
		Parser.log("input prop="+JSON.stringify(prop));
		Parser.parseAutoCompleteDataProvider(conf.id);
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.id = conf.id;
		data['i18nname-'+Parser.lang] = prop["i18nname-"+Parser.lang];
		data.databinding = prop.databinding;
		data.maxlength = prop.maxlength;
		data.style = Parser.cssDisplay(prop.display)+(prop.style?prop.style:"")+(prop.margintop?"margin-top:"+prop.margintop:"");
		var fmdcols = parseInt(conf.fmdcols);
		Parser.log("input fmdcols="+fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		var transform = {"tag":"i"};
		transform.html = '<div class="col-md-'+cols[0]+'">'+
			    '<p'+
			    (prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '') +
			    (prop.hideLabel=='1' ? ' style="display:none;"' : '')+
			    '>'+prop["i18nname-"+Parser.lang]+
			    (required ? '<span class="xh">*</span>' : '') +
			    (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')+
			    '</p>'+
			    '</div>'+
			    '<div class="col-md-'+cols[1]+'">'+
		       '<input type="text" '
				+ (prop.disabled=='1' ? ' readonly="readonly"' : '')
				+ (data.style ? ' style="'+data.style+'"' : '')
				+ (' class="form-control '+(prop.classNames ? prop.classNames : '')+'"')
				+ ' databinding="${databinding}"'
				//+ (prop.processbinding ? ' binding="'+ prop.processbinding+ '"' : '')
				+ ' maxlength="${maxlength}"' 
				+ ' id="${id}"'
				+ ' desc="${i18nname-'+Parser.lang+'}"'
				+ ' name="${id}"'
				+ ' ng-model="b.'+prop.databinding+'"'
				+ ' placeholder="'+(prop.placeholder?prop.placeholder:'')+'"'
				+ '/>'
				+ '</div>';
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

Parser["control:input:default:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log("input conf="+JSON.stringify(conf));
		Parser.log("input prop="+JSON.stringify(prop));
		Parser.parseAutoCompleteDataProvider(conf.id);
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.id = conf.id;
		data['i18nname-'+Parser.lang] = prop["i18nname-"+Parser.lang];
		Parser.log("inputvalue"+data['i18nname-'+Parser.lang]);
		data.databinding = prop.databinding;
		data.maxlength = prop.maxlength;
		data.style = Parser.cssDisplay(prop.display)+(prop.style?prop.style:"")+(prop.margintop?"margin-top:"+prop.margintop:"");
		var fmdcols = parseInt(conf.fmdcols);
		Parser.log("input fmdcols="+fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		var transform = {"tag":"i"};
		transform.html = '<span class="label label1 col-md-'+cols[0]+'"'
							+ (data.style ? ' style="'+data.style+'"' : '')
							+ ">"
							+ '<p'
							+ (prop["i18ntip-"+Parser.lang] ? (' title='+prop["i18ntip-"+Parser.lang]+'') : '')
							+ (prop.hideLabel=='1' ? ' style="display:none;"' : '')
							+ '>'
							+ (required ? '<span class="xh">*</span>' : '')
							+ '${i18nname-'+Parser.lang+'}'
							+ (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')
							+ '</p></span>'
							+ '<span class="item item1 cellborder col-md-'+cols[1]+'"'
							+ (data.style ? ' style="'+data.style+'"' : '')
							+ '><input type="text" '
							+ (prop.disabled=='1' ? ' readonly="readonly"' : '')
							+ (' class="form-control '+(prop.classNames ? prop.classNames : '')+'"')
							+ ' databinding="${databinding}"'
							//+ (prop.processbinding ? ' binding="'+ prop.processbinding+ '"' : '')
							+ ' maxlength="${maxlength}"' 
							+ ' id="${id}"'
							+ ' desc="${i18nname-'+Parser.lang+'}"'
							+ ' name="${id}"'
							+ ' ng-model="b.'+prop.databinding+'"'
							+ '/>'
							+ (prop.attachment=='1' ? '<span class="attachspan" attach-tag="'+(prop.attachmentTag || conf.id)+'">'
								+ (prop.attachmentEditable=='1' ? '<button class="btnupload" title="'+fmd_i18n_prop_upattach+'">&nbsp;'+fmd_i18n_modules.input.attachment+'&nbsp;</button>' : '')
								+ '</span>' : '')
							+ '</span>';
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

